home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 4.5 KB | 90 lines | [TEXT/GEOL] |
- Item 3758968 7-Feb-91 13:32PST
-
- From: CDA0461 DEV Symplex Software,IDV
-
- To: CPLUS.DEV$ C++ Interest List--Developers
- CPLUS.APPLE$ C++ Interest List--Apple Employees
-
- ------------------------------------------------------------------------------
-
- Sub: C++ Virt.Fncs: no A5 needed
-
- [Okay, I admit I'm confused. I always thought that the CPLUS.DEV$ archives
- were simply archives of past discussions in the C++ Discussion folder. Now I
- discover that the two areas are parallel universes, complete with concurrent
- discusssions on the feasiblity of virtual functions in standalone code.
- Bizarre. So, my apologies if you have already seen this post.]
-
- > We need to solve the problem with virtual functions though...
-
- Virtual functions can be used with standalone code: they do not
- require an A5-world. I have prototyped a post processor that
- takes the output from CFront and transforms the code and the virtual
- function tables so that it will work within the single code resource
- environment of things like XCMDs. I intend to use
- this for my future use in XCMDs and other standalone code. Warning:
- if you thought the Beard A5-world technique was dependent on the
- current CFront implementation, you probably would scream at the
- the amount of implementation dependent processing I do. The concept
- is certainly not implementation dependent, but I basically have to
- change every initialization and use of virtual tables and the
- pointers to them. One advantage of my method is that the virtual tables
- are initialized at link time rather than at runtime.
-
- There are some problems
-
- 1) The post processing of the CFront table has to produce an assembly
- language file as well as the C file. The asembly language file
- is used to define the virtual function tables as *constant* data
- within the code segment. MPW C provides no support for this
- (except for string constants). This is similar to the problem
- that CFront has with Object Pascal linkages: the dispatch
- tables cannot be output as C code.
-
- 2) The main output file is still C. This means that the access to
- the virtual function has to be expressed as C expressions and
- cannot be optimized to the most efficient machine language form
- There is also the problem that MPW C does not generate optimal
- code for some C expressions required. A further problem is that
- the MPW Linker only performs its "A5 offset to PC relative"
- transformation magic to the instructions JSR, JMP, LEA and PEA:
- this further limits the operations that can be applied to global
- "data" (that is, the transformed virtual tables) that turn out
- being PC relative. All of this affects performance, but I don't
- think the "hit" is that high. (No, I haven't counted cycles nor
- optimized the expressions to the compiler yet.)
-
- [ ... and a couple more problems that weren't in the original post ...]
-
- 3) The initial prototype was done as a MPW shell editing script so performance
- is, um, poor. I haven't looked at the stream editor that apparently will come
- with MPW 3.2: perhaps that will improve things or perhaps I'll eventually bite
- the bullet and translate the post-processor into C. [Or maybe something like
- Perl?]
-
- 4) The Beard A5-world technique could be extended to support global variables
- and static member functions. My address-to-offset technique does not provide
- support for these features: it addresses only the issue of virtual functions,
- but I don't think this limitation is any more severe than the restrictions when
- writing standalones in C.
-
- So the answer is that virtual functions within standalone code
- are feasible and they don't require creation of an A5 world.
- Future versions of CFront could incorporate this approach without
- requiring drastic changes, but optimal code generation may require
- a version of CPlus that generates object code directly. It is
- possible to do this yourself with the current version of MPW C++,
- but you have to be willing to accept a post-CFront pre-C
- processing step that is sensitive to changes in the CFront
- translator.
-
- ----------------------------------------------------------------------
- John Miller (604) 433-1795
- Symplex Systems AppleLink (rarely) CDA0461 (soon to be SYMPLEX)
- Burnaby, British Columbia Fax: (604) 430-8516
- Canada usenet: john_miller@mindlink.uucp <== best
-
- Macintosh Consulting & Software Development
- ----------------------------------------------------------------------
-
-